package net.tavion.angelboot.common.utils;

import org.springframework.http.server.reactive.ServerHttpRequest;
import reactor.core.publisher.Mono;

public class WebFluxUtils {

    static final Class<ServerHttpRequest> CONTEXT_KEY = ServerHttpRequest.class;

    public static Mono<ServerHttpRequest> getServerHttpRequest() {
        return Mono.subscriberContext()
                .map(ctx -> ctx.get(CONTEXT_KEY));
    }


    public static Mono<String> getHeader(String name){
        return  getServerHttpRequest().flatMap(
              request -> Mono.just(request.getHeaders().getFirst(name))
        );
    }


}
